#include "head.hpp"

int main()
{
    // 1.创建共同的key值
    key_t key = ftok(PATH_SHM, ID);
    assert(key != -1);
    cout << "创建key值成功, key: " << endl;

    // 2.获取共享内存
    int shmid = shmget(key, SHM_SIZE, 0);
    assert(shmid != -1);
    cout << "获取共享内存成功, shmid " << shmid << endl;

    // 3.关联共享内存
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    assert(shmaddr != nullptr);
    cout << "关联共享内存成功, shmaddr: " << shmaddr << endl;

    // 4. 这里为通信逻辑...

    // 5.去关联
    int n = shmdt(shmaddr);
    assert(n != -1);
    cout << "去关联成功, n: " << n << endl;

    return 0;
}